package con.shake;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class BootReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(final Context context, final Intent bootintent) {
		try {
			SharedPreferences sharedPreference = PreferenceManager
					.getDefaultSharedPreferences(context);

			boolean isServiceRunningValue = sharedPreference.getBoolean(
					ShakeApp.KEY_IS_SERVICE_RUNNING, false);
			boolean isServiceRunning = Utils.isServiceRunning(context,
					MyService.class);
			if (isServiceRunningValue) {
				if (!isServiceRunning) {
					context.startService(new Intent(context, MyService.class));
					isServiceRunning = true;
				}
			} else {
				if (isServiceRunning) {
					context.stopService(new Intent(context, MyService.class));
					isServiceRunning = false;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
